package hhh.app.presenter.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.zhy.adapter.abslistview.CommonAdapter;
import com.zhy.adapter.abslistview.ViewHolder;

import java.util.List;

import hhh.app.R;
import hhh.app.data.bean.Category;

/**
 * Created by hhh on 2017/1/4.
 */
public class CategoryAdapter extends CommonAdapter<Category> {
    private View.OnClickListener onClickListener;
    private OnItemClickListener onItemClickListener;

    private Context context;
    private List<Category> categories;

    public CategoryAdapter(Context context, int layoutId, List<Category> datas) {
        super(context, layoutId, datas);
        init();
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }


    private void init() {
        onClickListener=new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ViewHolder holder= (ViewHolder) v.getTag();
                if(onItemClickListener!=null){
                    onItemClickListener.onItemClickListener(v,holder.getItemPosition());
                }
            }
        };
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v=super.getView(position, convertView, parent);
        v.setOnClickListener(onClickListener);
        return v;
    }

    @Override
    protected void convert(ViewHolder viewHolder, Category item, int position) {
        viewHolder.setText(R.id.ci_label,item.getName());
    }

    public interface OnItemClickListener{
        public void onItemClickListener(View v,int pos);
    }

}
